package com.jyh.blog.strategy.context;

import com.jyh.blog.dto.ArticleSearchDTO;
import com.jyh.blog.strategy.ArticleSearchStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static com.jyh.blog.enums.SearchModeEnum.getSearchMode;

@Service
public class ArticleSearchStrategyContext {
    @Value("${search.mode}")
    private String mode;
    @Autowired
    private Map<String, ArticleSearchStrategy> articleSearchStrategyMap;

    public List<ArticleSearchDTO> executeArticleSearch(String keywords){
        return articleSearchStrategyMap.get(getSearchMode(mode)).ArticleSearch(keywords);
    }
}
